﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改图标</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>
    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">功能名称</label>
            <div class="layui-input-inline">
                <input type="text" name="functionname" id="functionname" lay-verify="required" placeholder="请输入功能名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">功能简称</label>
            <div class="layui-input-inline">
                <input type="text" name="functionremark" id="functionremark" lay-verify="required" placeholder="请输入功能简称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管辖菜单</label>
            <div class="layui-input-inline">
                <textarea name="managemenu" rows="5" readonly="readonly" lay-verify="required" id="managemenu" placeholder="请选择管辖菜单" class="layui-textarea"></textarea>
                <input id="menuid" class="form-control" name="menuid" type="hidden" value="">
            </div>
            <button style="float: left;" type="button" onclick="select_menu()" data-type="add" class="layui-btn">选择管辖菜单</button>
        </div>
        <div class="layui-form-item" lay-filter="sex">
            <label class="layui-form-label">是否可用</label>
            <div class="layui-input-block">
                <input type="checkbox" id="isactive" checked="" name="open" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="可用|禁用">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
        </div>
    </div>

    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/js/jquery.min2.1.4.js"></script>
    <script src="../../../layuiadmin/js/jshelp.js"></script>
    <script>
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var editid = getUrlParam('editid');
        var arr_id = {};

        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'upload'], function () {
            var $ = layui.$
                , form = layui.form
                , upload = layui.upload;
            
            //加载修改信息
            $.ajax({
                url: 'ashx/list.ashx?type=getlist_byid&editid=' + editid,
                type: 'GET',
                success: function (data) {
                    var str = "";
                    for (var i = 0; i < data.data.length; i++) {

                        $("#functionname").val(data.data[i].name);
                        $("#functionremark").val(data.data[i].remark);
                        $("#managemenu").val(data.data[i].menunames);
                        $("#menuid").val(data.data[i].menuids);
                        var menuids = data.data[i].menuids;
                        var menuids_arr = menuids.split(",");
                        arr_id = new Array();
                        for (var j = 0; j < menuids_arr.length; j++) {                          
                            arr_id.push(menuids_arr[j]);
                        }
                        var isactive = $("#isactive").prop("checked");//是否可用
                        if (data.data[i].isactive == 'Y') {
                            $("#isactive").attr("checked", "checked");
                            $("#isactive").attr("value", '可用');
                        }
                        else {
                            $("#isactive").removeAttr("checked");
                            var x = document.getElementsByClassName("layui-unselect layui-form-switch layui-form-onswitch");
                            x[0].setAttribute("class", "layui-unselect layui-form-switch");
                            var d = document.getElementsByTagName('em')[0];
                            d.firstChild.nodeValue = '禁用';
                        }
                    }
                    arr_id.join(",");
                }
            })
           
        })
        //选择管辖店铺
        function select_menu() {
            layer.open({
                type: 2
                , title: '选择管辖菜单'
                , content: 'select_menu.html'
                , maxmin: true
                , area: ['600px', '550px']
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-front-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var obj = $(layero).find("iframe")[0].contentWindow;
                        var mJson = eval(obj.$('#uidsub').val());//获取子页面控件绑定的值
                        arr_id = new Array();
                        var arr_name = new Array();
                        for (var i = 0; i < mJson.length; i++) {
                            arr_id.push(mJson[i].id);
                            arr_name.push(mJson[i].title);
                            if (mJson[i].children != undefined) {
                                var children_ii = mJson[i].children;
                                if (children_ii.length > 0) {
                                    for (var ii = 0; ii < children_ii.length; ii++) {
                                        arr_id.push(children_ii[ii].id);
                                        arr_name.push(children_ii[ii].title);
                                        if (children_ii[ii].children != undefined) {
                                            var children_iii = children_ii[ii].children;
                                            if (children_iii.length > 0) {
                                                for (var iii = 0; iii < children_iii.length; iii++) {
                                                    arr_id.push(children_iii[iii].id);
                                                    arr_name.push(children_iii[iii].title);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        arr_id.join(",");
                        arr_name.join(",");
                        $('#managemenu').val(arr_name);
                        $('#menuid').val(arr_id);
                        layer.close(index); //关闭弹层
                    });

                    submit.trigger('click');
                }
            });
        }
       
    </script>
</body>
</html>